package com.ly.work.practice;

public class SingleTest {
    //私有化构造器
    private SingleTest(){};

    //声明对象
    public static SingleTest singleTest = null;

    public static SingleTest getSingleTest(){
        //第一层判断
        if (singleTest==null){
            //同步锁
            synchronized (Object.class){
                //第二层判断
                if (singleTest==null){
                    singleTest = new SingleTest();
                    System.out.println("创建完成");
                }
            }
        }
        return singleTest;
    }

}
